<template>
	<view class="content">
		<!-- 头部 开始 -->
		<view class="balance_container">
			<view class="balance">
				<view class="left">
					<view class="name">
						{{order_piece}}
					</view>
					<view class="title">
						订单单数(总)
					</view>
				</view>
				<view class="right">
					<view class="name">
						¥{{order_amount}}
					</view>
					<view class="title">
						订单金额(总)
					</view>
				</view>
			</view>
		</view>

		<!-- 头部 结束 -->
		<!-- 分销记录 开始 -->
		<view class="list_all">
			<view class="list" v-for="(item,index) in TeamPiecePageList" :key="index">
				<view class="left">
					<view class="tit">
						<image :src="imgUrl+item.avatar" mode=""></image>
						<text class="name">
							{{item.nickname}}
						</text>
					</view>
					<view class="con">
						订单单数：{{item.order_piece}}单
					</view>
				</view>
				<view class="right">
					订单金额：{{item.order_amount}}元
				</view>
			</view>
		</view>
		<!-- 分销记录 结束 -->
		<view class="no_thing" v-if="noOrder">
			<image src="../../../static/icon/no_order.png"></image>
			<view class="no_thing_text">暂无内容</view>
		</view>
		<view class="over" v-if="flag">我也是有底线的</view>
		<is-login v-on:childClick='listenToClose' v-on:childClickAgain='listenToCloseAgain' v-if="isLogin==0"></is-login>
	</view>
</template>

<script>
	import isLogin from '../../../components/isLogin.vue'
	import {
		uniIcons
	} from '@dcloudio/uni-ui'
	export default {
		components: {
			uniIcons,
			isLogin
		},
		data() {
			return {
				TeamPiecePageList: [],
				count: '',
				isLogin: 1,
				page: 1,
				limit: 15,
				imgUrl: '',
				flag: false,
				noOrder: false,
				order_amount: null,
				order_piece: null
			}
		},
		onLoad() {
			let that = this
			this.imgUrl = that.$imgUrl
			if (!uni.getStorageSync('openid')) {
				this.isLogin = 0
			} else {
				this.getTeamPiecePageList()
			}
		},
		onPullDownRefresh() {
			this.page = 1
			// this.tremList = []
			this.flag = false
			this.noOrder = false
			uni.showToast({
				icon: 'loading',
				title: '加载中',
			});
			setTimeout(() => {
				this.getTeamPiecePageList(() => {
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
			}, 1000)
		},
		onReachBottom() {
			if (this.TeamPiecePageList.length < this.page * this.limit) {
				return this.flag = true
			}
			this.noOrder = false
			this.page++
			this.getTeamPiecePageList()
		},
		methods: {
			getTeamPiecePageList(callback) {
				let that = this
				var data = {
					openid: uni.getStorageSync('openid'),
					page: that.page,
					limit: that.limit
				}
				this.$myRequest.post(this.$api.distribution.getTeamPiecePage, data).then(res => {
					if (res.code == '200') {
						callback && callback()
						that.order_amount = res.data.order_amount
						that.order_piece = res.data.order_piece

						that.count = res.data.count
						if (that.page == 1) {
							if (res.data.data.length == 0) {
								return this.noOrder = true
								this.flag = false
							}
							if (res.data.data.length <= this.limit) {
								this.flag = true
							}
							this.TeamPiecePageList = res.data.data
						} else {
							this.TeamPiecePageList = [...this.TeamPiecePageList, ...res.data.data]
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			listenToClose(msg) {
				this.isLogin = msg
			},
			listenToCloseAgain() {
				this.getTeamPiecePageList()
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 690rpx;
		margin: 0 auto;

		.balance_container {
			position: sticky;
			top: 0;
			left: 0;
			right: 0;
			margin: auto;
			height: 140rpx;

			.balance {
				margin-top: 22rpx;
				width: 100%;
				height: 120rpx;
				background: #FFFFFF;
				box-shadow: 0px 2rpx 10rpx 0px rgba(90, 96, 105, 0.14);
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				text-align: center;
				position: -webkit-sticky;

				.left {
					flex: 1;
					border-right: 2rpx solid #E6E8EF;

					.name {
						font-size: 30rpx;
						color: #294D7C;
					}

					.title {
						font-size: 26rpx;
						color: #333333;
					}
				}

				.right {
					flex: 1;

					.name {
						font-size: 30rpx;
						color: #294D7C;
					}

					.title {
						font-size: 26rpx;
						color: #333333;
					}
				}
			}
		}


		.list_all {
			.list {
				border-bottom: 1rpx solid #E5E5E5;
				display: flex;
				justify-content: space-between;
				margin-bottom: 28rpx;

				.left {
					.tit {
						display: flex;
						align-items: center;

						image {
							height: 64rpx;
							width: 64rpx;
							margin: 0 17rpx 19rpx 0;
						}

						.name {
							color: #333333;
							font-size: 26rpx;
						}
					}

					.con {
						color: #777777;
						font-size: 24rpx;
						padding-bottom: 20rpx;
					}
				}

				.right {
					color: #777777;
					font-size: 24rpx;
					margin-top: 84rpx;
				}
			}
		}
	}
</style>
